package cn.edu.sjtu.tooling.dto;

import cn.edu.sjtu.tooling.domain.Task;
import cn.edu.sjtu.tooling.enums.ECNStateEnum;
import cn.edu.sjtu.tooling.enums.TaskStateEnum;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Data;

import java.util.Date;

@Data
@Builder
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
public class StateDTO {

  private String taskId;
  private String processId;
  private Date time;
  private Integer status;
  private MockData data;
  private MockInfo info;

  public static StateDTO ofTaskState(Task task) {
    return StateDTO.builder()
        .taskId(task.getTaskId())
        .processId(task.getProcessId())
        .time(new Date())
        .status(task.getStatus().ordinal())
        .data(MockData.genRandomData())
        .info(MockInfo.genFixedInfo())
        .build();
  }

  public static StateDTO ofECNState(ECNStateEnum ecnStateEnum) {
    return StateDTO.builder().time(new Date()).status(ecnStateEnum.ordinal()).build();
  }

  public static StateDTO ofTaskPendingState() {
    return StateDTO.builder().time(new Date()).status(TaskStateEnum.PENDING.ordinal()).build();
  }
}
